<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript"
      src="http://ditu.googleapis.com/maps/api/js?key=AIzaSyDR9h5ndRRCRqan6Hs2EXV9q_NsXUFbxXc&sensor=true">
    </script>
    <script type="text/javascript" src="StageWebViewBridge.js"></script>
    <script type="text/javascript">
      var marker;
      var map;
    
      function initialize() {
    	  var location = getQueryString("location");
        var myOptions = {
          center: new google.maps.LatLng(31.23093, 121.473704),
          zoom: 14,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
        
        var infowindow = new google.maps.InfoWindow();

        marker = new google.maps.Marker({
            position: map.getCenter(),
            map: map
        });

        google.maps.event.addListener(marker, 'click', (function(marker) {
          return function() {
            infowindow.setContent("asas");
            infowindow.open(map, marker);
          }
        })(marker));

        google.maps.event.addListener(map, 'click', function(event){
        	   placeMarker(event.latLng);
        });
      }
      
      function placeMarker(location) {
    	  marker.setMap(null);
    	  marker = new google.maps.Marker({
    	      position: location,
    	      map: map
    	  });
    	  
    	  callAs3Funciton();
    	}
      
      
      function getMakerLocation() {
    	  return marker.position;
      }
      
      function callAs3Funciton() {
    	  StageWebViewBridge.call('fnCalledFromJS', null, marker.position);
      }
      
      function initLocation(lat, lng) {
    	  var location = new google.maps.LatLng(lat, lng);
    	  map.setCenter(location);
    	  placeMarker(location);
      }
      
      function getQueryString(name) {
          var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
          if (reg.test(location.href)) return unescape(RegExp.$2.replace(/\+/g, " ")); return "";
      }
    </script>
</head>
<body onload="initialize()">
   <div id="map_canvas" style="width:100%; height:100%;"></div>
</body>
</html>